package com.bjsxt.controller;

import com.bjsxt.model.Result;
import com.bjsxt.modle.AccountVo;
import com.bjsxt.service.AccountService;
import com.bjsxt.util.SpringSecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * description:
 * 用户财产记录控制层
 *
 * @author ALIENWARE
 * @version v1.0.0
 * @create 5/1/2024
 **/
@RestController
@RequestMapping("/account")
@Api(tags = "用户财产记录控制器")
public class AccountController {
    /**
     * 用户财产记录业务层
     */
    @Autowired
    private AccountService accountService;

    /**
     * 获取当前用户的货币资产情况
     *
     * @param coinName 币种名称
     * @return 统一响应对象
     */
    @GetMapping("/{coinName}")
    @ApiOperation(value = "获取当前用户的货币资产情况", authorizations = {@Authorization("Authorization")})
    public Result<AccountVo> getUserAccount(@ApiParam(value = "币种名称", required = true) @PathVariable String coinName) {
        // 获取当前登录对象的 userId
        Long userId = SpringSecurityUtils.getCurrentUserId();
        // 调用业务层方法查询对象并返回
        return Result.success(accountService.getByUserIdAndCoinName(userId, coinName));
    }
}
